package lx9_UDP小案例;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class Send {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        DatagramSocket ds = new DatagramSocket(8091);
        DatagramPacket dp = new DatagramPacket(new byte[16],0,InetAddress.getByName("127.0.0.1"),8090);
        String s = "";
        while(true){
            s = sc.next();

            //DatagramPacket dp = new DatagramPacket(s.getBytes(),s.getBytes().length, InetAddress.getByName("127.0.0.1"),8090);
            dp.setData(s.getBytes());
            dp.setLength(s.getBytes().length);

            ds.send(dp);
            if("886".equals(s))break;
        }
        ds.close();
        /*
        * UDP 三种通信方式
        * 1.单播
        * 2.组播：对一组电脑发送消息
        * 3.广播：对所有电脑
        * */
    }
}
